/*
 * PacketReceiverWrapper.h
 *
 *  Created on: Sep 16, 2017
 *      Author: zjf
 */

#ifndef SRC_TCPSERVERPACKETRECEIVERWRAPPER_H_
#define SRC_TCPSERVERPACKETRECEIVERWRAPPER_H_

#include <Poco/Types.h>
#include <Poco/Timestamp.h>
#include <Poco/Net/NetException.h>

#include "PacketReceiver.h"

using namespace Poco;
using namespace Poco::Net;
using namespace utils;

namespace network
{

template<typename PacketType, typename PacketReaderWriterType>
class TCPServerPacketReceiverWrapper: public utils::PacketReceiver<PacketType, PacketReaderWriterType>
{
public:
	TCPServerPacketReceiverWrapper(PacketReaderWriterType& io);
	virtual ~TCPServerPacketReceiverWrapper();

	typename PacketType::Ptr recv();

private:
	int recv(char *buff, int size);

	PacketReaderWriterType& _io;
	PacketType _packet;
	UInt32 _readLen = 0;
	int _timeout = 0;
};

} /* namespace network */


#endif /* SRC_TCPSERVERPACKETRECEIVERWRAPPER_H_ */
